package de.tudresden.st.cbse.calendar.user;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;

import de.tudresden.st.cbse.calendar.Calendar;

@Entity
public class User implements Serializable {
    private static final long serialVersionUID = 4866489536941372294L;
    
    @Id
	private String email;
	private String password;
	private String name;
	
	@OneToOne(cascade=CascadeType.ALL)
	private Calendar calendar;
	
	@Deprecated
	public User() {
	}
	
	public User(String name, String email, String password) {	    
		this.calendar = new Calendar();
		this.name = name;
		this.email = email;
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public Calendar getCalendar() {
		return calendar;
	}
	
	public boolean check(String password) {
		return this.password.equals(password);
	}

	
	@Override
	public boolean equals(Object other) {
		if (other instanceof User) {
			return this.email.equals(((User) other).email);
		}
		
		return false;
	}
	
	@Override
	public int hashCode() {
		return 42 * this.email.hashCode();
	}
}
